package com.myosw.action;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;

import com.myosw.entity.PageShow;
import com.myosw.entity.SearchlogShow;
import com.myosw.entity.VisitlogShow;
import com.myosw.service.FilterService;
import com.myosw.service.SearchlogService;
import com.myosw.service.ServiceService;
import com.myosw.service.VisitlogService;

public class UserAction extends BaseAction {

	public void index() throws ServletException, IOException {
		root.put("menu", "index");
		printFreemarker("default/default.ftl", root);
	}
	
	public void service() throws ServletException, IOException {
		root.put("menu", "service");
		String[] params = request.getParams();
		int size = 10;
		int pagecount = 1;
		if(params!=null){
			if(params.length>0)
				pagecount = Integer.parseInt(params[0]);
			if(params.length>1)
				size = Integer.parseInt(params[1]);
		
		}
	
		PageShow page = serviceService.getUrls(pagecount , size );
		root.put("page", page);
		printFreemarker("default/service.ftl", root);
	}
	
	public void filter() throws ServletException, IOException {
		 root.put("menu", "filter");
		 
		 String[] params = request.getParams();
			int size = 10;
			int pagecount = 1;
			if(params!=null){
				if(params.length>0)
					pagecount = Integer.parseInt(params[0]);
				if(params.length>1)
					size = Integer.parseInt(params[1]);
			}
		
			PageShow page = filterService.getFilters(pagecount , size );
			root.put("page", page);
		 
		printFreemarker("default/filter.ftl", root);
		 
	}
	
	public void keyword() throws ServletException, IOException {
		 List<SearchlogShow> list = searchlogService.getTop(0, 10);
			
		 root.put("list", list);
		root.put("menu", "keyword");
		printFreemarker("default/keyword.ftl", root);
	}
	
	public void visit() throws ServletException, IOException {
	 List<VisitlogShow> list = visitlogService.getTop(0, 10);
		root.put("list", list);
		root.put("menu", "visit");
		printFreemarker("default/visit.ftl", root);
	}
	
	ServiceService serviceService = new ServiceService();
	FilterService filterService = new FilterService();
	SearchlogService searchlogService = new SearchlogService();
	VisitlogService visitlogService = new VisitlogService();
}
